#pragma once
#include "../basic/singleton.hpp"
#include <Windows.h>

class CWaitForEvent : public Singleton<CWaitForEvent> {
  friend class Singleton<CWaitForEvent>;
  CWaitForEvent() = default;

public:
  void create();
  void start();
  void stop();
  void close();
  bool need_run(int times);
};

extern HANDLE STOP_EVENT;

#define WaitStopReturnValue(WAITTIME, RETURNVALUE)                             \
  if (WaitForSingleObject(STOP_EVENT, WAITTIME) == WAIT_OBJECT_0) {            \
    return RETURNVALUE;                                                        \
  }

#define WaitStopReturn(WAITTIME)                                               \
  if (WaitForSingleObject(STOP_EVENT, WAITTIME) == WAIT_OBJECT_0) {            \
    return;                                                                    \
  }

#define WaitStopBreak(WAITTIME)                                                \
  if (WaitForSingleObject(STOP_EVENT, WAITTIME) == WAIT_OBJECT_0) {            \
    break;                                                                     \
  }

#define WaitSleep(WAITTIME)                                                    \
  if (WaitForSingleObject(STOP_EVENT, WAITTIME) == WAIT_OBJECT_0) {            \
  }
